//
//  BALNetworkSecurityHelper.m
//  BALPractice
//
//  Created by zhuhao on 15/3/7.
//  Copyright (c) 2015年 zhuhao. All rights reserved.
//

#import "BALNetworkSecurityHelper.h"
#import <CommonCrypto/CommonDigest.h>

@implementation BALNetworkSecurityHelper

+ (NSString *)stringToMD5:(NSString *)string
{
    if (nil == string)
    {
        return nil;
    }
    
    const char *cStr = [string UTF8String];
    unsigned char digest[CC_MD5_DIGEST_LENGTH];
    
    if (CC_MD5(cStr, (CC_LONG)strlen(cStr), digest))
    {
        NSMutableString *hex = [NSMutableString string];
        
        for (int i = 0; i < CC_MD5_DIGEST_LENGTH; i++)
        {
            [hex appendFormat:@"%02x", (int)(digest[i])];
        }
        
        return hex;
    }
    
    return nil;
}

@end
